package com.sanxia.equipment.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.sanxia.equipment.vo.SupplierVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.sanxia.equipment.domain.Supplier;
import com.sanxia.equipment.service.ISupplierService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商列表Controller
 *
 * @author 贤哥编程
 * @date 2023-04-25
 */
@RestController
@RequestMapping("/supplier/supplier")
public class SupplierController extends BaseController
{
    @Autowired
    private ISupplierService supplierService;



    @GetMapping("/supplieLlist")
    public TableDataInfo supplieLlist()
    {
        List<Supplier> list = supplierService.selectSupplierLists();
        return getDataTable(list);
    }


    /**
     *  审批操作
     * @param
     * @return
     */

    @PreAuthorize("@ss.hasPermi('supplier:supplier:approver')")
    @Log(title = "供应商列表", businessType = BusinessType.UPDATE)
    @PutMapping("/approver")
    public AjaxResult approverSupplier(@RequestBody SupplierVo supplierVo)
    {
        return toAjax(supplierService.approverSupplier(supplierVo));
    }

    /**
     *  审核操作
     * @param
     * @return
     */

    @PreAuthorize("@ss.hasPermi('supplier:supplier:audit')")
    @Log(title = "供应商列表", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditSupplier(@RequestBody SupplierVo supplierVo)
    {
        return toAjax(supplierService.audit(supplierVo));
    }



    /**
     * 查询供应商列表列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(Supplier supplier)
    {
        startPage();
        List<Supplier> list = supplierService.selectSupplierList(supplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:supplier:export')")
    @Log(title = "供应商列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Supplier supplier)
    {
        List<Supplier> list = supplierService.selectSupplierList(supplier);
        ExcelUtil<Supplier> util = new ExcelUtil<Supplier>(Supplier.class);
        util.exportExcel(response, list, "供应商列表数据");
    }

    /**
     * 获取供应商列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:supplier:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return success(supplierService.selectSupplierBySupplierId(supplierId));
    }

    /**
     * 新增供应商列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:supplier:add')")
    @Log(title = "供应商列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Supplier supplier)
    {
        supplier.setAuditStatus(0);
        supplier.setCreateTime(new Date());
        supplier.setCreateBy( SecurityUtils.getUsername());
        return toAjax(supplierService.insertSupplier(supplier));
    }

    /**
     * 修改供应商列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:supplier:edit')")
    @Log(title = "供应商列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Supplier supplier)
    {
        supplier.setUpdateBy(SecurityUtils.getUsername());
        supplier.setUpdateTime(new Date());
        return toAjax(supplierService.updateSupplier(supplier));
    }

    /**
     * 删除供应商列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:supplier:remove')")
    @Log(title = "供应商列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(supplierService.deleteSupplierBySupplierIds(supplierIds));
    }
}
